package com.fatdetection.demo.controller;

import com.fatdetection.demo.annotation.AuthAdmin;
import com.fatdetection.demo.annotation.AuthOperator;
import com.fatdetection.demo.bean.ProjGroup;
import com.fatdetection.demo.service.GroupSevice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/group")
@AuthAdmin
@AuthOperator
public class GroupController {
    @Autowired
    GroupSevice groupSevice;

    @GetMapping("/getGroupsByProjId/{projectId}")
    public Object getGroupsByProjId(@PathVariable Integer projectId){
        List<ProjGroup> data = groupSevice.getGroupsByProjId(projectId);
        return data;
    }
    @PostMapping("/add")
    public Boolean insertGroup(ProjGroup projGroup){
        return groupSevice.insertGroup(projGroup);
    }

    @PostMapping("/del")
    public Boolean delGroup(Integer groupId){
        return groupSevice.delGroup(groupId);
    }

    @PostMapping("/update")
    public Boolean updateGroup(ProjGroup group){
        return groupSevice.updateGroup(group);
    }

    @GetMapping("/findByName/{groupName}")
    public ProjGroup findByName(@PathVariable String groupName){
        return groupSevice.findByGroupName(groupName);
    }

    @GetMapping("/findAll")
    public List<ProjGroup> findAll(){
        List<ProjGroup> list = groupSevice.findAll();
        return list;
    }

    @GetMapping("/findByProj/{projectName}")
    public List<ProjGroup> findByProj(@PathVariable("projectName") String projectName){
        List<ProjGroup> list = groupSevice.findByProj(projectName);
        return list;
    }

    @GetMapping("/findByOpt/{optName}")
    public List<ProjGroup> findByOpt(@PathVariable("optName") String optName){
        List<ProjGroup> list = groupSevice.findByOpt(optName);
        return list;
    }

    @GetMapping("findBySchool/{schoolName}")
    public List<ProjGroup> findBySchool(@PathVariable("schoolName") String schoolName){
        List<ProjGroup> list = groupSevice.findBySchool(schoolName);
        return list;
    }

    @GetMapping("findById/{id}")
    public ProjGroup findById(@PathVariable("id")Integer id){
        ProjGroup projGroup = groupSevice.findById(id);
        return projGroup;
    }
}
